package com.example.demo.controller;

import com.example.demo.framework.IStudent;
import com.example.demo.framework.TestEvent;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/")
public class HomeController {

    @Autowired
    ApplicationContext applicationContext;
    private IStudent iStudent;
    public HomeController(IStudent iStudent){
        this.iStudent = iStudent;
    }
    @RequestMapping("/")
    @ResponseBody
    public String index(HttpServletRequest request, HttpServletResponse response, Model model){
        model.addAttribute("name","wang");
        iStudent.sayName();
        applicationContext.publishEvent(new TestEvent(this));

        return "hellow world!";
    }
}
